package apis

import (
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-admin-team/go-admin-core/sdk/api"
	"net/http"
	models2 "tuowei.com/app/admin/models"
	"tuowei.com/app/api/models"
	"tuowei.com/app/api/service"
	"tuowei.com/app/api/service/dto"
	"tuowei.com/pkg/xlog"
)

type ApiColleges struct {
	api.Api
}

func (e ApiColleges) Province(ctx *gin.Context) {
	e.MakeContext(ctx).MakeOrm()
	provinces := make([]models2.SysRegion, 0)
	err := e.Orm.Where("level = ?", 1).Find(&provinces).Error
	if err != nil {
		e.Error(http.StatusInternalServerError, err, err.Error())
		return
	}
	e.OK(provinces, "success")
}
func (e ApiColleges) SelectedList(c *gin.Context) {
	req := &dto.GetSelectedListReq{}
	s := service.ApiColleges{}
	err := e.MakeContext(c).MakeOrm().Bind(&req, binding.Default(c.Request.Method, c.ContentType())).MakeService(&s.Service).Errors
	if err != nil {
		xlog.Error(err)
		e.Error(500, err, err.Error())
		return
	}
	list := make([]models.Colleges, 0)
	count := int64(0)
	err = s.GetSelectedList(req, &list, &count)
	if err != nil {
		xlog.Error(err)
		e.Error(500, err, err.Error())
		return
	}

	e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
	return

}
